package com.sitech.openapi.componet;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.NativeWebRequest;

/**
 * @author LiJie
 * @Description
 * @date 2018/10/19
 */
@Component
public class SetHttpHeaderCmptImpl implements SetHttpHeaderCmpt {
    @Override
    public HttpHeaders setOKHttpHeaders(HttpHeaders httpHeaders) {
        String requestId = httpHeaders.getFirst("X-CTG-Request-ID");
        HttpHeaders header = new HttpHeaders();
        header.set("Content-Type",MediaType.APPLICATION_JSON_UTF8_VALUE);
        header.set("X-CTG-Request-ID",requestId);
        header.set("X-RateLimit-Limit","60");
        header.set("X-RateLimit-Remaining","48");
        header.set("X-RateLimit-Reset","14");
        return header;
    }

    @Override
    public HttpHeaders setErrorHttpHeaders(NativeWebRequest request) {
        String requestId = request.getHeader("X-CTG-Request-ID");
        HttpHeaders header = new HttpHeaders();
        header.set("Content-Type",MediaType.APPLICATION_PROBLEM_JSON_UTF8_VALUE);
        header.set("X-CTG-Request-ID",requestId);
        header.set("X-RateLimit-Limit","60");
        header.set("X-RateLimit-Remaining","48");
        header.set("X-RateLimit-Reset","14");
        return header;
    }
}
